package com.imooc.spark.streaming.utils

import java.util.{Date, Locale}

import org.apache.commons.lang3.time.FastDateFormat

/**
  * @description
  * @author yuyon26@126.com
  * @date 2018/10/5 15:27
  */
object DateUtils {

  /**
    * 输入文件日期格式：2018-12-12 12:12:12
    */
  val YYYYMMDDHHMM_TIME_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss")

  /**
    * 目标日期格式 ：20181212121212
    */
  val TARGET_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss")

  def parse(time: String) = {
    TARGET_FORMAT.format(new Date(getTime(time)))
  }

  /**
    * 获取输入日志时间
    *
    * @param time
    * @return long
    */
  def getTime(time: String) = {
    YYYYMMDDHHMM_TIME_FORMAT.parse(time).getTime
  }

  def main(args: Array[String]): Unit = {
    println(parse("2018-12-12 12:12:12"))
  }
}
